home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / comm / msged400.zip / src / bmg.c < prev    next >
C/C++ Source or Header  |  1996-06-20  |  1KB  |  53 lines

  1. /*
  2.  *  BMG.C
  3.  *
  4.  *  Written by Paul Edwards and released to the public domain.
  5.  *
  6.  *  Emulate Boyer-More-Gosper routines, without actually doing it, because
  7.  *  Msged doesn't use the proper functionality, for unknown reasons.
  8.  */
  9.  
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include "bmg.h"
  13. #include "strextra.h"
  14.  
  15. static char search_string[256];
  16.  
  17. void bmg_setsearch(char *search)
  18. {
  19.     strcpy(search_string, search);
  20. }
  21.  
  22. char *bmg_search(char *text)
  23. {
  24.     return bmg_find(text, search_string);
  25. }
  26.  
  27. char *bmg_find(char *text, char *search)
  28. {
  29.     char *endText, *p;
  30.     int lent, lens, searchStart;
  31.  
  32.     lent = strlen(text);
  33.     lens = strlen(search);
  34.     if (lens > lent)
  35.     {
  36.         return NULL;
  37.     }
  38.     searchStart = toupper(*search);
  39.     p = text;
  40.     endText = p + (lent - lens) + 1;
  41.     for (; p != endText; p++)
  42.     {
  43.         if (toupper(*p) == searchStart)
  44.         {
  45.             if (strncmpi(p, search, lens) == 0)
  46.             {
  47.                 return p;
  48.             }
  49.         }
  50.     }
  51.     return NULL;
  52. }
  53.